-
Notifications
You must be signed in to change notification settings - Fork 319
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Send Percy screenshots via npm script (not Jest) #3009
Conversation
21626e5
to
4a7a526
Compare
4a7a526
to
7194636
Compare
7194636
to
be60cac
Compare
be60cac
to
026b54c
Compare
@@ -140,7 +140,13 @@ jobs: | |||
|
|||
- description: JavaScript component tests | |||
name: test-component | |||
run: npx percy exec -- jest --color --selectProjects "JavaScript component tests" | |||
run: npx jest --color --maxWorkers=2 --selectProjects "JavaScript component tests" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without the CPU load from the @percy/puppeteer Chromium tabs we can now run JavaScript component tests with 2x workers
We use the same flag for JavaScript behaviour tests above
026b54c
to
9765f9e
Compare
9765f9e
to
c99ce8d
Compare
uses: ./.github/workflows/actions/install-node | ||
|
||
- name: Start review application | ||
run: npm run serve & |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starts the review app in the background using &
|
||
env: | ||
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }} | ||
PORT: 8888 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Review app uses port 3000
but our Puppeteer helpers want 8888
c99ce8d
to
c4dbaab
Compare
c4dbaab
to
5f4204c
Compare
5f4204c
to
568ca1a
Compare
.github/workflows/tests.yml
Outdated
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }} | ||
|
||
regression: | ||
name: Regression checks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we make it clearer that the checks happen 'in Percy' rather than as part of this action? Maybe naming this something like 'Send screenshots to Percy'?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah so this is the job name "Regression checks" which might include others in future?
The step name on line 189 says "Send screenshots to Percy"
Happy to make them match though
.github/workflows/tests.yml
Outdated
@@ -137,10 +137,12 @@ jobs: | |||
- description: JavaScript behaviour tests | |||
name: test-behaviour | |||
run: npx jest --color --maxWorkers=2 --selectProjects "JavaScript behaviour tests" | |||
cache: .cache/jest |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this related to the other changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was me noticing that we restore the .cache/jest
directory for all four Verify jobs
But didn't necessarily need it for:
npm run build:package
npm run build:dist
As we saw in the Windows runners often "restoring the cache" was slower than not having it.
The code was simpler before so I'll put it back
lib/puppeteer-helpers.js
Outdated
@@ -2,7 +2,7 @@ const { componentNameToJavaScriptClassName } = require('./helper-functions.js') | |||
const { renderHtml } = require('./jest-helpers.js') | |||
|
|||
const configPaths = require('../config/paths.js') | |||
const PORT = configPaths.ports.test | |||
const { PORT = configPaths.ports.test } = process.env |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I find this quite hard to read compared to e.g.
const { PORT = configPaths.ports.test } = process.env | |
cost PORT = process.env.PORT || configPaths.port |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah sorry you've said this before, I'll change it 👍
We've got a couple of others:
https://github.com/alphagov/govuk-frontend/blob/main/config/jest/server/start.mjs#L6
https://github.com/alphagov/govuk-frontend/blob/main/lib/puppeteer-helpers.js#L5
It looks clearer with multiple envs perhaps?
const {
ENV_1 = 'Fallback value 1',
ENV_2 = 'Fallback value 2',
ENV_3 = 'Fallback value 3',
ENV_4 = 'Fallback value 4',
ENV_5 = 'Fallback value 5'
} = process.env
tasks/screenshot-components.mjs
Outdated
* @param {string} screenshotName - Screenshot name | ||
* @returns {Promise<void>} | ||
*/ | ||
export async function screenshot (page, screenshotName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a benefit to wrapping percySnapshot
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For JSDoc perhaps at the time, let's remove it
// Screenshot each component | ||
const input = [...componentNames] | ||
|
||
// Screenshot 4x components concurrently |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How did you arrive at 4x? Might be useful to capture in the commit message in case we want to revisit in the future.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tried 5x initially but 4x was faster
Good point though, worth trying 2x and 3x as well (you never know!)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you click into the Send screenshots to Percy job to see the timings:
- 1x component in sequence govuk-frontend/actions/runs/5854565851 – ⏱️ 36 seconds
- 2x components concurrently govuk-frontend/actions/runs/3496480973 – ⏱️ 31 seconds
- 3x components concurrently govuk-frontend/actions/runs/3496481529 – ⏱️ 28 seconds
- 4x components concurrently govuk-frontend/actions/runs/3496493071 – ⏱️ 22 seconds
- 5x components concurrently govuk-frontend/actions/runs/5854480472 – ⏱️ 22 seconds
The total action time varies due to GitHub cache retrieval API times being wobbly
I'll keep it at 4x but add a comment
568ca1a
to
28ad3fb
Compare
Runs faster than “one at a time” by using multiple Chromium tabs. Once we go above 4x though we see little extra benefit See: #3009 (comment)
28ad3fb
to
398dee5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can tidy up a dependency we no longer need, but otherwise this looks good to me 👍🏻
@@ -101,7 +101,7 @@ We generate 2 screenshots for each default example of every component. One examp | |||
|
|||
The screenshots are public, so you can check them without logging in. A BrowserStack account is needed to approve or reject any changes (if you don't have access, ask your tech lead for help). If you're the reviewer of the pull request code, it's your responsibility to approve or request changes for any visual changes Percy highlights. | |||
|
|||
When you run the tests locally (for example, using `npm test`), Percy commands are ignored and Percy does not generate any screenshots. You will see the following message in your command line output: `[percy] Percy is not running, disabling snapshots`. | |||
When you run the tests locally (for example, using `npm run test:screenshots`), Percy commands are ignored and Percy does not generate any screenshots. You will see the following message in your command line output: `[percy] Percy is not running, disabling snapshots`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for keeping the docs in sync 🙌🏻
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@36degrees No problem. I didn't quite know if we should keep the test:*
prefix
Based on the "…‘tests’ aren’t really tests” feedback
But we can always revisit another day. Thanks again 😊
@@ -1,51 +0,0 @@ | |||
const { join } = require('path') | |||
const { fetch } = require('undici') | |||
const { WebSocket } = require('ws') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we now remove ws
from our dependencies? (Was introduced in 496cc38)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very nice, yep let's do that 🎉
Runs faster than “one at a time” by using multiple Chromium tabs. Once we go above 4x though we see little extra benefit See: #3009 (comment)
398dee5
to
93cde6f
Compare
This PR moves our Percy screenshots out of Jest following a recent conversation
This has added another big speed up to our checks